﻿using Acme.ConcreteMixDesign.Players;
using Acme.ConcreteMixDesign.Topics;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Data;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Domain.Repositories;
using Volo.Abp.Guids;

namespace Acme.ConcreteMixDesign.Data
{
    internal class ConcreteMixDesignDataSeedContributor : IDataSeedContributor, ITransientDependency
    {
        private readonly IRepository<Topic, Guid> _topicRepository;
        private readonly IRepository<Answer, Guid> _answerRepository;
        private readonly IRepository<Player, Guid> _playerRepository;
        private readonly List<Guid> _guids=new List<Guid>();
        Dictionary<AnswerType, Answer> answers = new Dictionary<AnswerType, Answer>();

        public ConcreteMixDesignDataSeedContributor(
            IGuidGenerator guidGenerator,
            IRepository<Topic, Guid> topicRepository,
            IRepository<Answer, Guid> answerRepository,
            IRepository<Player, Guid> playerRepository)
        {
            _topicRepository = topicRepository;
            _answerRepository = answerRepository;
            _playerRepository = playerRepository;

            for (int i = 0; i < 4; i++)
            {
                _guids.Add(guidGenerator.Create());
            }
        }
        public async Task CreatePlayerAsync()
        {
            var player = new Player(
                _guids[0],
                "123",
                "123",
                "lmw",
                "男",
                "gks",
                "rjgc",
                "211",
                "xs"
                );
            await _playerRepository.InsertAsync(player);
        }
        public async Task CreateAnswerAsync(Guid topicId)
        {

            Answer answer1 = new Answer(
                _guids[0],
              topicId,
                AnswerType.CalculateMixRatio,
                300,
                1,
                400,
                1.33,
                200,
                0.67,
                500,
                1.67
                );

            Answer answer2 = new Answer(
                _guids[1],
              topicId,
                AnswerType.TrialMixRatio,
                300,
                1,
                400,
                1.33,
                200,
                0.67,
                500,
                1.67
                );

            Answer answer3 = new Answer(
                _guids[2],
              topicId,
                AnswerType.BenchmarkMixRatio,
                300,
                1,
                400,
                1.33,
                200,
                0.67,
                500,
                1.67
                );

            Answer answer4 = new Answer(
                _guids[3],
              topicId,
                AnswerType.MixProportion,
                300,
                1,
                400,
                1.33,
                200,
                0.67,
                500,
                1.67
                );
            await _answerRepository.InsertAsync(answer1);
            await _answerRepository.InsertAsync(answer2);
            await _answerRepository.InsertAsync(answer3);
            await _answerRepository.InsertAsync(answer4);
            answers.Add(AnswerType.CalculateMixRatio, answer1);
            answers.Add(AnswerType.TrialMixRatio, answer2);
            answers.Add(AnswerType.BenchmarkMixRatio, answer3);
            answers.Add(AnswerType.MixProportion, answer4);
        }
        public async Task CreateTopicAsync()
        {
            var topic = new Topic(
                _guids[0],
                "题目1",
                "某现浇钢筋混凝土梁，混凝土设计强度等级C30，施工要求坍落度为35～50mm，使用环境为无冻害的室外\r\n使用。施工单位无该种混凝土的历史统计资料，该混凝土采用统计法评定。所用的原材料情况如下：\r\n1.水泥：42.5级普通水泥，实测28d抗压强度为46.0MPa，密度ρ c=3100kg／m³\r\n；\r\n2.砂：级配合格，Mx=2.7的中砂，表观密度ρ 0s=2650kg／m³\r\n；\r\n3.石子：5～20mm的碎石，表观密度ρ 0g=2720 kg／m³\r\n。\r\n\r\n"

                );
            await _topicRepository.InsertAsync(topic);
        }

        public async Task SeedAsync(DataSeedContext context)
        {
            await CreatePlayerAsync();
            await CreateTopicAsync();
            await CreateAnswerAsync(_guids[0]);

        }
    }
}
